import sys
from app.models import User
from app import create_app
from flask_jwt_extended import create_access_token
from datetime import timedelta

def generate_test_token(user_id=1):
    app = create_app('development')
    with app.app_context():
        user = User.query.get(user_id)
        if user:
            access_token = create_access_token(identity=user.id, expires_delta=timedelta(days=1))
            return access_token
        else:
            return None

if __name__ == '__main__':
    if len(sys.argv) > 1:
        try:
            user_id = int(sys.argv[1])
        except ValueError:
            print("Invalid user ID provided. Please provide an integer.")
            sys.exit(1)
    else:
        user_id = 1
    
    token = generate_test_token(user_id)
    if token:
        print(f"Generated token for user {user_id}: {token}")
    else:
        print(f"Failed to generate token, user {user_id} not found.") 